using System;
using System.Collections;
using System.Web;
using System.Web.SessionState;
using Sedna.Core.Common;

namespace Sedna.Core.Controller.Menu
{
	public class TopMenuAwareActionParam : IActionParam
	{
		public string Name
		{
			get { return "menu_level_1"; }
			set { throw new NotSupportedException(); }
		}

		public string GetValue(IExecutionContext executionContext)
		{
			string topMenuLevel = (string)executionContext["menu_level_1"];
			if(topMenuLevel == null)
			{
				topMenuLevel = MenuUtils.ExtractMenuLevel1Param(executionContext);
			}
			if(topMenuLevel == null || topMenuLevel == string.Empty)
			{
				topMenuLevel = ExtractFromSession(executionContext);
			}

			return topMenuLevel;
		}

        private string ExtractFromSession(IExecutionContext executionContext)
		{
			return (string)executionContext.GetScopedValue("infrastructure.menu_level_1", Scope.Session);
		}

	}
}
